package com.gljx.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gljx.web.Entity.TrainChargeEntry;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.TrainChargeEntryMapper;
import com.gljx.web.dao.TrainChargeMapper;
import com.gljx.web.service.TrainChargeEntryService;

@Transactional
@Service
public class TrainChargeEntryServiceImpl extends CommonDao implements TrainChargeEntryService{

	@Autowired
	private TrainChargeEntryMapper TrainChargeEntryMapper;
	
	@Autowired
	private TrainChargeMapper TrainChargeMapper;
	
		
		/**
		 * 实现删除
		 */
		@Override
		public void deleteTranChargeByFid(String[] deleteId, String fid) {
			// TODO Auto-generated method stub
			if(fid == null){
				for (int i = 0; i < deleteId.length; i++) {
					TrainChargeEntryMapper.deleteByFparentid(deleteId[i]);
					TrainChargeMapper.deleteByPrimaryKey(deleteId[i]);
				}
			}else{
				TrainChargeEntryMapper.deleteByFparentid(fid);
				TrainChargeMapper.deleteByPrimaryKey(fid);
			}
		}

		/**
		 * 根据父类id查询
		 */
		@Override
		public List<TrainChargeEntry> queryTrainChargeEntrysByFparentId(String fparentId) {
			// TODO Auto-generated method stub
			return TrainChargeEntryMapper.selectTrainChargeEntrysByFparentId(fparentId);
		}

		@Override
		public List<TrainChargeEntry> queryTrainChargeEntry(String fparentId, String studentName, String cfidcardno,
				String cftjr) {
			// TODO Auto-generated method stub
			   Map<String, Object> paramMap = new HashMap<String, Object>();
		       paramMap.put("v_fparentid", fparentId);
		       paramMap.put("v_studentName", studentName);
		       paramMap.put("v_cfidcardno", cfidcardno);
		       paramMap.put("v_cftjr",cftjr);
		       paramMap.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);
		       this.getSqlSession().select("com.gljx.web.dao.TrainChargeEntryMapper.selectTrainChargeEntry", paramMap, null);
		       //关闭数据库链接
		       @SuppressWarnings("unchecked")
		       List<TrainChargeEntry> trainChargeEntrys = (List<TrainChargeEntry>) paramMap.get("v_cursor");
		       return trainChargeEntrys;
		}

	@Override
	public List<TrainChargeEntry> selectTrainChargeByInfo(String studentName, String cfidcardno, String cftjr, String beginTime, String endTime, String companyId) {
		Map<String, String> map = new HashMap<>();
		map.put("studentName", studentName);
		map.put("cfidcardno", cfidcardno);
		map.put("cftjr", cftjr);
		map.put("beginTime", beginTime);
		map.put("endTime", endTime);
		map.put("companyId", companyId);
		return TrainChargeEntryMapper.selectTrainChargeByInfo(map);
	}

	@Override
	public List<TrainChargeEntry> selTrainByFnumber(String funmber, String userSession) {
		Map map = new HashMap();
			map.put("companyId",userSession);
			map.put("fnumber",funmber);
		return TrainChargeEntryMapper.selTrainByFnumber(map);
	}

	@Override
		public int insertSelective(TrainChargeEntry trainEntry) {
			// TODO Auto-generated method stub
			return TrainChargeEntryMapper.insertSelective(trainEntry);
		}

}
